package com.ruoyi.web.controller.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.service.ISysDeptService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

/**
 * 部门信息测试接口
 * 
 * @author ruoyi
 */
@Api(tags = "部门信息测试接口")
@RestController
@RequestMapping("/api/test/dept")
public class DeptTestController extends BaseController {
    
    @Autowired
    private ISysDeptService deptService;
    
    /**
     * 获取部门信息
     */
    @ApiOperation("获取部门信息")
    @GetMapping("/info/{deptId}")
    @Anonymous // 允许匿名访问，无需登录认证
    public AjaxResult getDeptInfo(
            @ApiParam(value = "部门ID", required = true, example = "100")
            @PathVariable("deptId") Long deptId) {
        SysDept dept = deptService.selectDeptById(deptId);
        if (dept != null) {
            return AjaxResult.success(dept);
        } else {
            return AjaxResult.error("部门不存在");
        }
    }
    
    /**
     * 获取所有部门列表
     */
    @ApiOperation("获取所有部门列表")
    @GetMapping("/list")
    @Anonymous // 允许匿名访问，无需登录认证
    public AjaxResult getDeptList() {
        SysDept dept = new SysDept();
        List<SysDept> depts = deptService.selectDeptList(dept);
        return AjaxResult.success(depts);
    }
    
    /**
     * 获取部门树结构
     */
    @ApiOperation("获取部门树结构")
    @GetMapping("/tree")
    @Anonymous // 允许匿名访问，无需登录认证
    public AjaxResult getDeptTree() {
        List<SysDept> depts = deptService.selectDeptList(new SysDept());
        return AjaxResult.success(depts);
    }
}